from config import *
from help import *
from routin import *
def draw_txt(painter, txt,x,y,yAdd, txtSize, pathSize, isone=False):
    y = y+yAdd
    if txt=='':
        return
  
    path = QPainterPath()
    font = QFont()
    font.setBold(True);        
    font.setFamily("Arial");
    font.setPixelSize(txtSize);            
    path.addText(x, y, font, txt);    
    pen = QPen()
    if isone:
        #pen.setColor(Qt.white)
        pen.setColor(QColor(255, 240, 123));
        #pen.setColor(Qt.black)
    else:        
        pen.setColor(Qt.white);        
    pen.setStyle(Qt.SolidLine);
    if not isone:
        pen.setWidth(pathSize);
    else:
        pen.setWidth(draw_txt_pathSize2);
        
    painter.setRenderHint(QPainter.Antialiasing);
    painter.strokePath(path, pen);
    if isone:
        painter.fillPath(path, QBrush(QColor(255, 240, 123)) );
        painter.fillPath(path, QBrush( Qt.white) );
        painter.fillPath(path, QBrush( Qt.black) );
    else:        
        painter.fillPath(path, QBrush(Qt.black));  
        
 
        
def drawCir(p,x,y, isR, w1, r1, w2, r2):
    pen = QPen()
    pen.setWidth(w1)
    pen.setColor(Qt.white)        
    p.setPen(pen)
    p.drawEllipse(QPoint(x,y),r1,r1)
    
    pen.setWidth(w2)
    if isR:
        pen.setColor(Qt.red)
    else:
        pen.setColor(Qt.black)
    p.setPen(pen)
    p.drawEllipse(QPoint(x,y),r2, r2)  

class wzi(QMainWindow):
    def __init__(self):
        super().__init__()                     
        self.setWindowFlags(Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint|Qt.ToolTip)
        if small_win_trans:
            self.setAttribute(Qt.WA_TranslucentBackground)
        self.setGeometry(0, 0, txt_win_size[0], txt_win_size[1])
        self.zi = ''
        self.isone = False
        
    def draw(self, zi, x, y, isone):
        update = False
        if self.zi != zi or self.isone != isone: 
            update = True
            self.zi = zi
            self.isone = isone
            
        if update:
            self.repaint()
        self.move(x-txt_gap, y-txt_gap)
        self.show()
        if update:
            self.repaint()        

    def paintEvent(self,e):
        p = QPainter (self);
        draw_txt(p, self.zi, txt_gap, txt_gap, draw_txt_yAdd, draw_txt_txtSize, draw_txt_pathSize, self.isone)
        
class wcir(QMainWindow):
    def __init__(self, isR, istop=False):
        super().__init__()                     
        self.setWindowFlags(Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint|Qt.ToolTip)
        if small_win_trans:
            self.setAttribute(Qt.WA_TranslucentBackground)
        self.setGeometry(0, 0, cir_win_size[0], cir_win_size[1])
        self.isR = isR
        self.istop = istop
        self.f = False
        
    def draw(self, x, y):
        self.move(x-cir_gap, y-cir_gap)
        self.show()    

    def paintEvent(self,e):
        p = QPainter (self);
        if not self.istop:
            drawCir(p, cir_gap, cir_gap, self.isR,draw_cir_out_width, draw_cir_out_rad, draw_cir_in_width, draw_cir_in_rad)
            return
        
        re = QRegion(0 , 0, cir_gap*2+5,cir_gap*2+5, QRegion.Ellipse);
        self.setMask(re)                 
        pen = QPen()
        qb = QBrush()
        qb.setColor(Qt.black)                    
        qb.setStyle(Qt.SolidPattern)        
        pen.setColor(Qt.white)                   
        pen.setWidth(cir_para[3])    
        p.setPen(pen)
        p.setBrush(qb)
        w =  cir_para[2]
        if not self.f:
            p.drawEllipse(QPoint(cir_gap,cir_gap),w,w)
        else:            
            p.drawRect(cir_gap-w, cir_gap-w, w*2, w*2) 
